package com.seecen;

import com.seecen.entity.Dept;
import com.seecen.mapper.DeptMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

public class Happy2 {
    public static void main(String[] args) throws InterruptedException {
        InputStream is = Happy1.class.getClassLoader().getResourceAsStream("mybatis.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        SqlSession session = factory.openSession();

        DeptMapper deptMapper = session.getMapper(DeptMapper.class);
        Dept dbDept = deptMapper.findByDeptno(1);
        dbDept.setDname("赣州");
        int row = deptMapper.updateDept(dbDept);
        if(row == 0) {
            System.out.println("乐观锁生效，修改失败，请重试");
        }
        Thread.sleep(20 * 1000);
        session.commit();
        session.close();
    }
}
